<?php 
    //p9m4t5d8

    require_once 'include/funcoes.php';
    checkLogado();
    
	$menu = array("perfil", "busca", "quemseguir", "amigos", "marcar", "meuslugares", "filtrar");
	
	$semIrPara = false;
	
    $_SESSION['usuario']['ultimaAtualizacao'] = date("Y-m-d H:i:s");   
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
		<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
		<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
		
		<title><?=PROJECT_NAME?></title>
		
<!--		<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />-->
		<link href="include/css/form.css" rel="stylesheet" type="text/css" />
		<link href="include/css/click.css" rel="stylesheet" type="text/css" />
		<link rel="stylesheet" href="include/css/milkbox/milkbox.css" media="screen" />
		<link rel="stylesheet" href="include/css/geral.css" media="screen" />
		<link href="include/css/datepicker_vista/datepicker_vista.css" rel="stylesheet" type="text/css" />
		
		<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>	
		<script type="text/javascript" src="include/js/mootools-core-1.4.3-full-compat-yc.js"> </script>
		<script type="text/javascript" src="include/js/mootools-more-1.4.0.1.js"> </script>	
		<script type="text/javascript" src="include/js/infoBox.js"> </script>	
		<script src="include/js/milkbox-yc.js"></script>
		<script type="text/javascript" src="include/js/readMap.js"> </script>
		<script type="text/javascript" src="include/js/datepicker.js"> </script>
		<script type="text/javascript" src="cluster/src/markerclusterer.js"></script>
		
		<script type="text/javascript">

		    var map;    
		    //var markers = [];
		    var latLngs = [];
		    var marcado = false;
		    var marker;

		    lat = "<?=$_SESSION['usuario']['posicaoInicial']['lat']?>";
		    lng = "<?=$_SESSION['usuario']['posicaoInicial']['lng']?>";
		    zoom = <?=$_SESSION['usuario']['posicaoInicial']['zoom']?>;

		    function initialize() {
			var myLatlng = new google.maps.LatLng(lat, lng);
			var myOptions = {
			zoom: zoom,
			center: myLatlng,
			mapTypeId: google.maps.MapTypeId.ROADMAP,
			mapTypeControl: false
		    }
		    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

		    google.maps.event.addListener(map, 'click', function(event) {
			if(!marcado){                                  
			    placeMarker(event.latLng); //coloca o marcador no mapa;
			}
			else{
			    marker.setMap(null);
			    placeMarker(event.latLng);
			}
			var input = marker.position.toString();
			var latlngStr =  input.split(",",2);
			var lat = latlngStr[0].replace("(","");
			var lng = latlngStr[1].replace(")","");
			$('latitude').set('value',lat);
			$('longitude').set('value',lng);
		    });
		}

		    function placeMarker(location) {    //coloca o mapa na posição 'position', com o ícone icon;

		      marker = new google.maps.Marker({
			      position: location,
			      map: map,				 
			      icon: getIcon() //pega o endereço da imagem do radio checado

		      });

			marcado = true;
		      //markers.push(marker.position);

		      //map.setCenter(location);
		    }

		    function getIcon(){
			    var radios = $$('input.radio');
			    var imgs = $$('img.imgIco');
			    var img;
			    var j;
			    for(i=0;i<radios.length;i++){	//pega a posição do radio checado para pegar a imagem de mesma posição
			    if(radios[i].checked)
			       j = i;
			    }
			    img = imgs[j];
			    return img.get('src');

		    }

		    function teste(){
			    return markers;
		    }



	    window.addEvent('domready', function(){

		    getUsuarios();

		    var save = new Request({
			    url: 'include/request/save.php'
		    });

		    $$('.save').addEvent('click',function(){
			    var m = teste();
			    save.post({markers:m});
		    });

		    $$('.deleteAll').addEvent('click',function(){
			    deleteOverlays();
		    });

		    $$('h2.item-acoes').addEvent('click',function(){
			    //$(this).getParent('li').;
		    });

	    });
		</script>
	</head>
	<body onload="initialize(); read1();">	
		<? require_once 'include/layoutUp.php'; ?>	
		<div class="fullscreen-map" id="map_canvas"></div>		
	</body>
	
	<script type="text/javascript" src="include/js/funcoes.js"> </script>
</html>
